*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
* SET GLOBAL $PATHS
*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
global root = "INSERT CUSTOMIZED PATH"
global source = "$root/code/calibrations/results/"
global output = "$root/data/processed/HealthProcess/"
global figures  =  "$root/figsandtabs/"
*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

set scheme s1mono
graph set window fontface "Garamond"

global size size(large)
global ls labsize(medlarge)
global legs medlarge


import excel using "${source}/Pspot_N_statexT.xlsx", sheet("Sheet1") firstrow clear

drop in 8

gen state = _n

reshape long Pspot_N, i(state) j(age)

replace age = age+24
replace Pspot_N=1000*Pspot_N

reshape wide Pspot_N, i(age) j(state)

gen agegr=floor(age/5)-5

collapse Pspot*, by(agegr)

merge 1:1 agegr using "${output}/prcere71"

keep if _merge==3
drop _merge

gen Pspot_NP=0
gen Psden=0

foreach num of numlist 3/7 {
replace Pspot_NP=Pspot_NP+fl`num'*Pspot_N`num'
replace Psden=Psden+fl`num'
}

replace Pspot_NP=Pspot_NP/Psden

/* FIGURE A11a */

twoway connect Pspot_N1  Pspot_N2  Pspot_NP agegr if agegr<10, ///
 legend(ring(0) pos(11) cols(1)  size($legs) order(3 "{&lambda}>2" 2 "{&lambda}=2" 1 "{&lambda}=1")) ///
  ytitle("Annual Premium  (P{sub:t}({&xi}{sub:t}); USD)", $size) xtitle("Age at Inception", $size) yscale(r(0 15000)) ///
 ylabel(0(5000)20000, $ls format( %12.0fc)) xlabel(0 "25-30" 2 "35-40" 4 "45-50" 6 "55-60" 8 "65-70", $ls) ///
  lcolor(black gs7 gs12)  mcolor(black gs7 gs12)

graph export "${figures}/pspot_NN.pdf", replace
